﻿using MediatR;
using SystemLYH.API.Application.Command.ReservoirCommand;
using SystemLYH.Infrstructre.Interface;

namespace SystemLYH.API.Application.Handlers.ReservoirHandlers
{
    public class ReservoirDeleteHandlers : IRequestHandler<ReservoirDeleteCommand, int>
    {
        protected readonly IReservoirRepository _reservoirRepository;
        /// <summary>
        /// 库区构造函数
        /// </summary>
        /// <param name="reservoirRepository"></param>
        public ReservoirDeleteHandlers(IReservoirRepository reservoirRepository)
        {
            _reservoirRepository = reservoirRepository;
        }
        public async Task<int> Handle(ReservoirDeleteCommand request, CancellationToken cancellationToken)
        {
            var list=(await _reservoirRepository.GetAllAsync()).Where(x=>request.ReservoirId.Contains(x.ReservoirId)).ToList();
            foreach (var item in list)
            {
                item.IsDelReservoir = true;
                await _reservoirRepository.UpdateAsync(item);
            }
            return 1;
        }
    }
}
